package cn.b.sky.modeler.util;

import com.fasterxml.uuid.EthernetAddress;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedGenerator;
import org.springframework.stereotype.Component;

/**
 * @Author: yueding
 * @Description:
 * @Date: Created in 18:15 2017/11/20
 * @Modified By:
 * Copyright(c) cai-inc.com
 */

@Component
public class UuidIdGenerator {
    protected static volatile TimeBasedGenerator timeBasedGenerator;

    public UuidIdGenerator() {
        this.ensureGeneratorInitialized();
    }

    protected void ensureGeneratorInitialized() {
        if(timeBasedGenerator == null) {
            Class var1 = UuidIdGenerator.class;
            synchronized(UuidIdGenerator.class) {
                if(timeBasedGenerator == null) {
                    timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
                }
            }
        }

    }

    public String generateId() {
        return timeBasedGenerator.generate().toString();
    }
}
